<template>
  <div class="task-item">
    <div class="task-header">
      <span class="task-lang">{{lang}}</span>
      <span class="task-module">{{ moduleName }}</span>
      <span class="task-level" :class="levelClass">{{ levelText }}</span>
    </div>
    
    <div class="task-content">
      <h3 class="task-title" :title="title">{{ title }}</h3>
      <div class="task-actions">
        <div class="action-button">
          <el-button type="primary" @click="previewTask" class="preview-button">
            <el-icon><View /></el-icon>
            预览
          </el-button>
        </div>
        <div class="action-button">
          <el-button type="success" @click="assignTask" class="assign-button">
            <el-icon><Check /></el-icon>
            分配
          </el-button>
        </div>
        <div class="action-button">
          <el-button type="danger" @click="checkTask" class="check-button">
            <el-icon><Search /></el-icon>
            检查
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: {
    id: Number,
    leave: Number,
    moduleName: String,
    title: String,
    lang: String,
    task: {
			type : Object,
			required: false,
		},
  },
  computed: {
    levelText() {
      const levels = ['', '简单', '中等', '困难', '选做'];
      return levels[this.leave] || '';
    },
    levelClass() {
      return {
        'level-easy': this.leave === 1,
        'level-medium': this.leave === 2,
        'level-hard': this.leave === 3,
        'level-optional': this.leave === 4
      }
    }
  },
  emits: ['preview-click', 'assign-click', 'check-click'],
  methods: {
    previewTask() {
      this.$emit('preview-click', this.task);
    },
    assignTask() {
      this.$emit('assign-click', this.id);
    },
    checkTask() {
      this.$emit('check-click', this.id, this.task);
    },
  }
}
</script>

<style scoped>
.task-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
  width: 100%;
  backdrop-filter: blur(8px);
}

.task-header {
    background: var(--el-text-color-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    padding: 10px 30px;
    border-radius: 10px;
}
.task-header > span {
	flex: auto 1 1 ;
	text-align: center;
}

.task-lang {
  font-size: 13px;
  color: #4a80ff;
  background: rgba(74, 128, 255, 0.15);
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
}

.task-module {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 12px;
  border-radius: 6px;
}

.task-level {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
}

.level-easy {
  color: #67c23a;
  background: rgba(103, 194, 58, 0.15);
}

.level-medium {
  color: #e6a23c;
  background: rgba(230, 162, 60, 0.15);
}

.level-hard {
  color: #f56c6c;
  background: rgba(245, 108, 108, 0.15);
}

.level-optional {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
}

.task-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  padding: 8px 0;
}

.task-title {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
  font-weight: 500;
  flex: 1;
  padding-right: 30px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-button {
  width: 100%;
}

/* 按钮背景色设置 */
.preview-button {
  background: rgba(74, 128, 255, 0.1) !important; /* 预览按钮透明背景色 */
  color: rgb(74, 128, 255) !important;
}

.assign-button {
  background: rgba(103, 194, 58, 0.1) !important; /* 分配按钮透明背景色 */
  color: rgb(103, 194, 58) !important;
}

.check-button {
  background: rgba(245, 108, 108, 0.1) !important; /* 检查按钮透明背景色 */
  color: rgb(245, 108, 108) !important;
}

:deep(.el-button) {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  border-radius: 6px;
  border: none; /* 去掉边框 */
  color: rgba(255, 255, 255, 0.9); /* 设置字体颜色 */
}

:deep(.el-icon) {
  font-size: 16px; /* 图标大小 */
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.task-item {
  animation: slideIn 0.3s ease-out;
}

.task-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.05),
    transparent
  );
  transition: 0.5s;
}

.task-item:hover::after {
  left: 100%;
}

@media screen and (max-width: 768px) {
  .task-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .task-title {
    padding-right: 0;
  }
  .task-actions {
    width: 100%;
    justify-content: flex-end;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .action-button {
    width: auto;
  }
}

@media screen and (max-width: 480px) {
  .task-actions {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }
  .action-button {
    width: auto;
    min-width: 0;
  }
}

</style>